#!/usr/bin/env bash

AWS_CLI_VERSION="2.0.30"
AWS_CLI_SHA="7ee475f22c1b35cc9e53affbf96a9ffce91706e154a9441d0d39cbf8366b718e"

if [ ! -d "/srv/zulip-aws-tools/v2/$AWS_CLI_VERSION" ]; then
    mkdir -p /srv/zulip-aws-tools
    cd /srv/zulip-aws-tools || exit 1
    rm -rf awscli.zip awscli.zip.sha256 aws/
    wget -q "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-$AWS_CLI_VERSION.zip" -O awscli.zip
    echo "$AWS_CLI_SHA  awscli.zip" >awscli.zip.sha256
    sha256sum -c awscli.zip.sha256
    unzip -q awscli.zip
    (
        cd ./aws || exit 1
        ./install -i /srv/zulip-aws-tools -b /srv/zulip-aws-tools/bin -u
    )
    rm -rf awscli.zip awscli.zip.sha256 aws/
fi

# shellcheck disable=SC2034
AWS="/srv/zulip-aws-tools/bin/aws"
